package shaders;

import helpers.ColorHelper;

import java.awt.Color;
import java.awt.image.BufferedImage;

import javax.vecmath.Vector3d;

import essential.Ray;

public class StoneShader extends Shader {

	public StoneShader(){
		per.persistence = 0.925;
		per.n = 6;
		spec = 0.25;
		int width = 1000;
		int height = 1000;
		
		textureImage = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);
	
	}
	
	@Override
	public Color calculateColor2d(int x, int y) {
		if(!textureIsSet){
			createTexture();
			textureIsSet = true;
		}
		
	return new Color(textureImage.getRGB(x, y));

	}

	@Override
	public Color calculateColor3d(Ray r, Vector3d sp) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Shader copy() {
		Shader s = new MatteShader();
		this.copyFromTo(this,s);
		return s;
	}


	@Override
	public double fBump(double x, double y, double z) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Color textureColor(double x, double y) {

	    double turbPower = 2.0; //makes twists
	    int turbSize = 100; //initial size of the turbulence

        double xyValue = turbPower * per.turbulence(x, y, turbSize) / 256.0;
              
        double amount = 256 * Math.abs((Math.sin(xyValue * 3.14159)));
	 
        
		amount = amount - Math.floor(amount);
		return  ColorHelper.sumColor(
				ColorHelper.mulColor(color, amount),
				ColorHelper.mulColor(gradientColor, 1-amount)
		);		
		
	}

	


}
